package com.ah.shanxi_demo.controller.file;
import com.ah.shanxi_demo.param.result.ConvertBase64FileRO;
import com.ah.shanxi_demo.param.result.SXResult;
import com.ah.shanxi_demo.service.IFileService;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

/**
 * @author Tao on 2020/7/24
 */
@RestController
@Api(value = "陕西高速", description = "陕西高速-文件服务")
@RequestMapping(value = "/api/v1/shanxi/file/", produces = "application/json; charset=UTF-8")
public class ApiFileController {

    @Autowired
    private IFileService fileService;

    @ApiOperation(value = "银行卡列表接口", notes = "银行卡列表接口")
    @RequestMapping(value = "bank_test", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String test1(
            @ApiParam(value = "参数", required = true) @RequestBody List<Integer> policyIdList) {
        String string = JSON.toJSONString(policyIdList);
        System.out.println(string);

        return string;
    }

    @ApiOperation(value = "导入EXCEL模板", notes = "导入EXCEL模板")
    @RequestMapping(value = "importFile", method = RequestMethod.POST)
    @Validated
    @CrossOrigin
    public SXResult<Object> importFile(MultipartFile file, String type) {
        SXResult<Object> importExcel = fileService.importExcel(file, type);
        return importExcel;
    }

    @ApiOperation(value = "文件转换base64", notes = "文件转换base64")
    @RequestMapping(value = "convertBase64", method = RequestMethod.POST)
    @Validated
    @CrossOrigin
    public SXResult<ConvertBase64FileRO> convertBase64File(MultipartFile multipartFile) {
        ConvertBase64FileRO base64File = fileService.convertBase64File(multipartFile);
        return  SXResult.instance(base64File);
    }


    @ApiOperation(value = "EXCEL模板下载", notes = "EXCEL模板下载")
    @RequestMapping(value = "excelDownLoad", method = RequestMethod.POST)
    @Validated
    @CrossOrigin
    public SXResult<Boolean> excelDownLoad(String fileName,Integer fileType) {
        Boolean downloadFile = fileService.downloadFile(fileName, fileType);
        return  SXResult.instance(downloadFile);
    }
}
